package com.netcracker.studies;

import Bank.Account;
import Beans.AuthorizationBeanInterface;
import DBConnection.DBAPI;
import DBConnection.DBTools;
import org.apache.log4j.Logger;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;


@WebServlet(name = "GetAccounts")
public class GetAccounts extends BaseServlet {

    private static final Logger log = Logger.getLogger(GetAccounts.class);

    protected void handlePostRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void handleGetRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        HttpSession session = request.getSession(true);
        AuthorizationBeanInterface a = (AuthorizationBeanInterface) session.getAttribute("UserBean");
        List<Bank.Account> accs = DBAPI.getAccountsByUserID(new BigInteger(a.getUserId()));
        if (session.getAttribute("accs") != null)
            session.removeAttribute("accs");
        session.setAttribute("accs", accs);
       // response.getWriter().write("accounts.jsp");
        request.getRequestDispatcher("accounts.jsp").forward(request, response);
//
    }
}
